﻿products = [['iphone', 6888], ['MacPro', 14800], ['小米6', 2499], ['Coffee', 31], ['Book', 60], ['Nike', 699]]

shop_list = dict()
shop_cart = dict()
cost = 0


def shop_add(c: int):
    global cost
    if shop_list[c][0] not in shop_cart:
        shop_cart[shop_list[c][0]] = 1
    else:
        shop_cart[shop_list[c][0]] += 1
    cost = cost + shop_list[c][1]
    print('商品\033[32;1m{}\033[0m添加成功！'.format(shop_list[c][0]))


print('-------商品列表-------')
for i, v in enumerate(products):
    shop_list[i + 1] = v
    print('{}\t{:<8}\t{:>6}'.format(i + 1, *v))
while True:
    choose = input('请输入你要选择的商品编号(1-6):')
    if choose == 'q':
        break
    elif choose in set(str(123456)):
        shop_add(int(choose))
    else:
        print('\033[31;1m输入不合法，请重新输入！\033[0m')
if not shop_cart:
    print('还未添加任何商品！')
    exit()
print('------账单------')
print('{}\t\t{}'.format('品名', '数量'))
for k, v in shop_cart.items():
    print('{}\t\t{:>3}'.format(k, v))
print('合计', cost, sep='\t\t')
